package cn.tanghom.app.oa.model;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import lombok.Data;

import org.springframework.data.jpa.domain.AbstractPersistable;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.index.TextIndexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import cn.tanghom.support.shiro.Functions;

import com.unbiz.common.collection.Stack;
import com.unbiz.common.lang.BaseObject;

import org.springframework.data.annotation.Id;
import org.springframework.format.annotation.DateTimeFormat;
/**
 * 人才与简历的区别是一个人才有多份简历，为简化业务，这里人才和简历是等价的，多份简历的user_key标识同一个人才
 * @author Hunteron-cp
 *
 */
@Data
@Document(collection="hd_talent")
public class Talent extends AbstractPersistable<Long>{	
	
	private static final long serialVersionUID = 1L;

	public static String collection = "hd_talent";	
	
	public String name;
	public String user_key;
	public String email;
	public String phone;
	
	public Integer cityId;
	
	@Field("company_name")
	@TextIndexed(weight=1)
	public String companyName;
	
	@TextIndexed(weight=4)
	public String jobTitle;
	
	public String school;
	
	@Field("anualSalary")
	public Integer annualSalary;	
	
	public String expect_city;
	
	public Integer expect_annual_salary;
	
	public String expect_industry;
	
	//title ids use expect_function
	@TextIndexed(weight=4)
	public String expect_position_titles;
	
	public Integer start_work_year;
	
	private Integer birthYear;
	
	private Integer gender;
	
	private Integer degreeId;
		
	@Field("uid")
	private Integer hunterId; //猎头Id
	
	@Field("id")
	private Integer talentId; //人才Id 和 主键相同
	
	@Field("resume_id")
	private Integer resumeId;  //简历Id
	
	public Long textContentId; //简历txt文本
	
	public Long htmlContentId; //简历html文本
	
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
	private Date createTime = new Date();
	
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
	private Date updateTime; // 更新时间
	
	public int status = 0;
	
	public Integer level; 
		
	public List<String> certificateList; //证书
	
	public Long categoryId;//分类ID	
	
	public int getAge(){
		if(birthYear<=0){
			return 0;
		}
		return 2018 - birthYear;
	}
	
	@Data	
	@Document(collection="hd_talent_work_exp")
	public static class WorkExp extends AbstractPersistable<Long> {
			
		public String start_time;
		public String end_time;
		
		public String company_name;
		public String position;	
		public String description;
		
		@Indexed
		@Field("resume_id")
		public Long resumeId;
		
		int step = 0;
		
		WorkExp(){
			
		}
		
		public WorkExp(String start){
			start_time = start;
			if(start!=null){
				step++;
			}
		}
		
		public WorkExp(String start,String end){
			start_time = start;
			end_time = end;
			if(start!=null){
				step++;
			}
		}	
	};
	
	@Data	
	@Document(collection="hd_talent_edu_exp")
	public static class EduExp extends AbstractPersistable<Long> {
			
		String start_time;
		String end_time;

		String school;
		String profession;	
		String degree;
		
		int step = 0;	
		
		@Indexed
		@Field("resume_id")
		public Long resumeId;		

		EduExp(){			
		}
		
		public EduExp(String start){
			start_time = start;
			if(start!=null){
				step++;
			}
		}
		
		public EduExp(String start,String end){
			start_time = start;
			end_time = end;
			if(start!=null){
				step++;
			}
		}
		
	}
	
	@Data	
	@Document(collection="hd_talent_project_exp")
	public static class ProjectExp extends AbstractPersistable<Long> {
			
		String start_time;
		String end_time;
		
		String company_name;
		String project_name;	
		String description;
		
		String project_job_title;
		
		String project_duty;
		
		@Indexed
		@Field("resume_id")
		public Long resumeId;
		
		int step = 0;
		
		ProjectExp(){
			
		}
		
		public ProjectExp(String start){
			start_time = start;
			if(start!=null){
				step++;
			}
		}
		
		public ProjectExp(String start,String end){
			start_time = start;
			end_time = end;
			if(start!=null){
				step++;
			}
		}	
	};
	
	public transient List<WorkExp> works;
	
	public transient List<EduExp> edus;	
	
	public transient List<ProjectExp> projects;	
	
	public Talent(Long id) {		
		this(id, null);
	}
	
	
	public Talent(Long id, String name) {		
		this.setId(id);
		this.name = name;
	}
	
	Talent() {
		
	}
	
	public String getFullName() {
        return jobTitle+" "+this.user_key;
    }
	
	public String getCategoryName() {
        return Functions.category(categoryId).getName();
    }
	
	@Override
    public Talent clone() {       
        return this;
    }
}
